package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.ItemTrialService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.ItemSearchBo;
import com.ddwl.schema.bo.goods.ItemTrialBo;
import com.ddwl.schema.bo.goods.ItemTrialDetBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.ItemConListVo;
import com.ddwl.schema.vo.goods.ItemTrialVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/itemTrial")
@Api(tags = "商品审核服务")
public class ItemTrialController extends BaseController {

    @Autowired
    private ItemTrialService itemTrialService;

    @PostMapping("list")
    @ApiOperation("获取审核列表(根据审核阶段，审核状态查询审核列表)")
    public RestVo<PageVo<ItemTrialVo>> queryList(@Valid @RequestBody PageBo<ItemTrialBo> pageBo) {
        return RestVo.ok(itemTrialService.list(pageBo));
    }

    //阶段为创建的在复审阶段通过后更新
    @PostMapping("approvePass")
    @ApiOperation("通过审批")
    public RestVo approvePass(@Valid @RequestBody ItemTrialDetBo itemTrialDetBo) {
        itemTrialService.approvePass(itemTrialDetBo);
        return RestVo.ok();
    }
    

    @PostMapping("approveRefuse")
    @ApiOperation("拒绝审批")
    public RestVo approveRefuse(@Valid @RequestBody ItemTrialDetBo itemTrialDetBo) {
        itemTrialService.approveRefuse(itemTrialDetBo);
        return RestVo.ok();
    }

    //阶段为复审的不插入下一阶段的“待审核”状态的信息
    //初审提交审批必须是要初审审批通过后才能提交审批
    @PostMapping("submitApprove")
    @ApiOperation("提交审批")
    public RestVo<Integer> submitApprove(@Valid @RequestBody ItemTrialDetBo itemTrialDetBo) {
        return RestVo.ok(itemTrialService.submitApprove(itemTrialDetBo));
    }


    @PostMapping("cancelApprove")
    @ApiOperation("撤销审批")
    public RestVo cancelApprove(@Valid @RequestBody ItemTrialDetBo itemTrialDetBo) {
        itemTrialService.cancelApprove(itemTrialDetBo);
        return RestVo.ok();
    }


    @PostMapping("undercarriage")
    @ApiOperation("申请下架")
    public RestVo undercarriage(@RequestBody ItemTrialBo itemTrialBo){
        itemTrialService.undercarriage(itemTrialBo);
        return RestVo.ok();
    }


    @PostMapping("undercarriageList")
    @ApiOperation("下架申请列表")
    public RestVo<PageVo<ItemConListVo>> undercarriageList(@RequestBody PageBo<ItemSearchBo> pageBo){
        return RestVo.ok(itemTrialService.undercarriageList(pageBo));
    }

    @PostMapping("undercarriageRefuse")
    @ApiOperation("下架申请驳回")
    public RestVo undercarriageRefuse(@RequestBody ItemTrialBo itemTrialBo){
        itemTrialService.undercarriageRefuse(itemTrialBo);
        return RestVo.ok();
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        itemTrialService.changeId();
        return RestVo.ok();
    }

}
